﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using Finance.Entites;
using Finance.UI.ViewModels;

namespace Finance.UI.ConfigPages
{
    public partial class SubPayoutClassificationConfig : PhoneApplicationPage
    {
        public SubPayoutClassificationConfig()
        {
            InitializeComponent();
            Loaded += (o, e) => InilizeDataContext();
        }

        private void InilizeDataContext()
        {
            var dataContext = new SettingPageViewModel();
            var subType = string.Empty;
            try
            {
                subType = NavigationContext.QueryString["subType"];
            }
            catch { }
            if (string.IsNullOrEmpty(subType))
            {
                NavigationService.GoBack();
            }
            else
            {
                var items = App.PayoutClassificationDataStore.Items.Where(item => item.Group == subType);
                foreach (var item in items)
                {
                    dataContext.ConfigGroups.Add(new SettingSelectItemViewModel()
                    {
                        CurrentConfigItemName = item.Name,
                    });
                }
            }

            this.DataContext = dataContext;
        }

        private void abibSave_Click(object sender, EventArgs e)
        {
            //TODO: Save config action
            NavigationService.Navigate(new Uri("/AccountSettingPage.xaml", UriKind.RelativeOrAbsolute));
        }

        private void abibBack_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/AccountSettingPage.xaml", UriKind.RelativeOrAbsolute));
        }
    }
}